
var pathSum = function(root, targetSum) {
  let res = []
  const dfs = (root,arr,sum) => {
    if(!root) return 
    arr.push(root.val)
    sum += root.val
    if(!root.left&&!root.right&&sum===targetSum) {
      return res.push(arr)
    }
    dfs(root.left,[...arr],sum) 
    dfs(root.right,[...arr],sum)
  }
  dfs(root,[],0)
  return res
};